home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Utilities / RemoteCommand / Source / AskOperator.m < prev    next >
Encoding:
Text File  |  1993-06-09  |  4.1 KB  |  134 lines

  1. // -------------------------------------------------------------------------------------
  2. // AskOperator
  3. // -------------------------------------------------------------------------------------
  4. // Permission is granted to freely redistribute this source code, and to use fragments
  5. // of this code in your own applications if you find them to be useful.  This class,
  6. // along with the source code, come with no warranty of any kind, and the user assumes
  7. // all responsibility for its use.
  8. // -------------------------------------------------------------------------------------
  9.  
  10. #import <appkit/appkit.h>
  11. #import <libc.h>
  12. #import <stdlib.h>
  13. #import <c.h>
  14. #import <sys/param.h>
  15. #import <sys/types.h>
  16. #import <sys/time.h>
  17. #import "AskOperator.h"
  18. #import "RemoteCommand.h"
  19.  
  20. // -------------------------------------------------------------------------------------
  21. @implementation AskOperator
  22.  
  23. // -------------------------------------------------------------------------------------
  24. // initialization
  25. // -------------------------------------------------------------------------------------
  26.  
  27. + new
  28. {
  29.     static    id    _self = (id)nil;
  30.     if (!_self) _self = [[self alloc] init];
  31.     return _self;
  32. }
  33.  
  34. - init
  35. {
  36.     [super init];
  37.     [NXApp loadNibSection:"AskOperator.nib" owner:self];
  38.     return self;
  39. }
  40.  
  41. // -------------------------------------------------------------------------------------
  42. // view control
  43. // -------------------------------------------------------------------------------------
  44.  
  45. - hideView:aView
  46. {
  47.     if ([aView isKindOf:[Button class]]) {
  48.         [aView setEnabled:NO];
  49.         [aView setTransparent:YES];
  50.         [aView setTitle:""];
  51.     } else
  52.     if ([aView isKindOf:[TextField class]]) {
  53.         [aView setStringValue:""];
  54.         [aView setEnabled:NO];
  55.         [aView setBezeled:NO];
  56.         [aView setBackgroundGray:NX_LTGRAY];
  57.         [aView setBackgroundTransparent:YES];
  58.         [[aView superview] addSubview:self:NX_BELOW relativeTo:(id)nil];
  59.     } else 
  60.         printf("hideView: unsupported View type %s\n", [aView name]);
  61.     return self;
  62. }
  63.  
  64. - unhideView:aView title:(const char*)title
  65. {
  66.     if ([aView isKindOf:[Button class]]) {
  67.         [aView setTitle:title];
  68.         [aView setEnabled:YES];
  69.         [aView setTransparent:NO];
  70.     } else
  71.     if ([aView isKindOf:[TextField class]]) {
  72.         [aView setBackgroundTransparent:NO];
  73.         [aView setStringValue:title];
  74.         [aView setEnabled:YES];
  75.         [aView setBezeled:YES];
  76.         [aView setBackgroundGray:NX_WHITE];
  77.         [[aView superview] addSubview:self:NX_ABOVE relativeTo:(id)nil];
  78.     } else 
  79.         printf("unhideView: unsupported View type %s\n", [aView name]);
  80.     return self;
  81. }
  82.  
  83. - fillView:aView title:(const char*)title dontHide:(BOOL)dontHide
  84. {
  85.     if ((title && *title) || dontHide) [self unhideView:aView title:title];
  86.     else [self hideView:aView];
  87.     return self;
  88. }
  89.  
  90. // -------------------------------------------------------------------------------------
  91. // message panels
  92. // -------------------------------------------------------------------------------------
  93.  
  94. - buildAskPanel:(askOperator_t*)ao
  95. {
  96.     char    *dftButton1 = (ao->button[0] && *ao->button[0])? ao->button[0]: "Continue";
  97.     [askPanel setTitle:ao->title];
  98.     [askMessage setStringValue:ao->message];
  99.     [self fillView:askText    title:ao->text      dontHide:(ao->type == 1)];
  100.     [self fillView:askButton1 title:dftButton1    dontHide:NO ];
  101.     [self fillView:askButton2 title:ao->button[1] dontHide:NO ];
  102.     [self fillView:askButton3 title:ao->button[2] dontHide:NO ];
  103.     [self fillView:askButton4 title:ao->button[3] dontHide:NO ];
  104.     return self;
  105. }
  106.  
  107. + (const char*)showAskPanel:(askOperator_t*)ao
  108. {
  109.     self = [self new];
  110.     [self buildAskPanel:ao];
  111.     textResponse = (const char*)nil;
  112.     buttonResponse = (const char*)nil;
  113.     [askPanel center];
  114.     [askPanel display];
  115.     [askPanel makeKeyAndOrderFront:(id)nil];
  116.     [NXApp runModalFor:askPanel];
  117.     [askPanel orderOut:(id)nil];
  118.     return (ao->type == 0)? buttonResponse : textResponse;
  119. }
  120.  
  121. // -------------------------------------------------------------------------------------
  122. // operator responses
  123. // -------------------------------------------------------------------------------------
  124.  
  125. - askButtonResponse:sender
  126. {
  127.     buttonResponse = [sender title];
  128.     textResponse = [askText isEnabled]? [askText stringValue] : (const char*)nil;
  129.     [NXApp abortModal];
  130.     return self;
  131. }
  132.  
  133. @end
  134.